package Enum;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lenovo
 * Date: 2022-09-20
 * Time: 17:09
 */


public enum TestEnum {
    RED("red",7),BLACK("red",5),GREEN("green",8),WHITE("w",18);//枚举对象


    String color;
    public int original;
    //构造方法
    TestEnum(String color, int original) {
        this.color = color;
        this.original = original;
    }

    TestEnum() {
    }

    public static void main9(String[] args) {
        TestEnum[] enums = TestEnum.values();
        for (int i = 0; i < enums.length; i++) {
            System.out.println(enums[i]+" " + "序号:"+enums[i].ordinal());
        }
    }
    public static void main3(String[] args) {
//拿到枚举实例BLACK
        TestEnum testEnum0 = TestEnum.BLACK;
//拿到枚举实例RED
        TestEnum testEnum1 = TestEnum.RED;
        System.out.println(testEnum0.compareTo(testEnum1));
        System.out.println(BLACK.compareTo(RED));
        System.out.println(RED.compareTo(BLACK));
    }
    //Enum.values 方法将枚举转化为数组
    public static void main2(String[] args) {
       TestEnum[] enums = TestEnum.values();
        for (int i = 0; i < enums.length; i++) {
            System.out.println(enums[i]+" " + "序号:"+enums[i].ordinal());
        }
        System.out.println("=======");
        //将字符串转化为枚举类型,但是enum里必须已经存在这个枚举类型
        TestEnum enumI = TestEnum.valueOf("GREEN8");
        System.out.println(enumI);
    }
    public static void main1(String[] args) {
       TestEnum testEnum2 = TestEnum.BLACK;
        switch (testEnum2) {
            case RED:
                System.out.println("red");
                break;
            case BLACK:
                System.out.println("black");
                break;
            case WHITE:
                System.out.println("WHITE");
                break;
            case GREEN:
                System.out.println("green");
                break;
            default:
                break;
        }
    }
}
